﻿@model ESN.Models.LiveFolder

@{
    ViewBag.Title = "View";
}
<script type="text/javascript">
    $(function () {
        // image preview function, demonstrating the ui.dialog used as a modal window
        function viewLargerImage(link, title) {
            var img = $("<img alt='" + title + "' style='display: none; padding: 8px;' />")
					.attr("src", link).appendTo("body");
            img.dialog({
                title: title,
                modal: true
            });
        }
        $("#dialog:ui-dialog").dialog("destroy");

        $(".zoomImg").click(function () {
            //viewLargerImage($(this).attr("data-href"), $(this).attr("title"));
            $("#dialog-modal").append('<img alt="image" src="' + $(this).attr("data-href") + '" style="max-width:' + $(window).width()*0.95 + 'px" />');
            $("#dialog-modal").dialog({
                width: $(window).width(),
                title: $(this).attr("title"),
                modal: true
            });
        });
        $(".deleteAtt").click(function () {
            var link = $(this);
            $.getJSON('/CoreService.svc/DeleteAttchment/?id=' + $(this).attr("data-id"), function (data) {
                if (data.d.DeleteAttchment) {
                    link.parent().hide("explode");
                }
            });
        });
        $(".setCover").click(function () {
            var link = $(this);
            $.getJSON('/CoreService.svc/SetAlbumCover/?id=' + $(this).attr("data-id"), function (data) {
                alert(data.d.SetAlbumCover);
            });
        });
    });
</script>
<h2>@Model.FName</h2>
<div id="dialog-modal"></div>
<div>
    <form id="uploadForm" action="/Collection/Upload" method="post" enctype="multipart/form-data">
        <input type="hidden" name="FId" id="FId" value="@Model.FId" />
        <input type="file" name="file" id="file" />
        <input type="submit" value="Upload" />
    </form>
</div>
<hr />
<ul id="gallery" class="gallery ui-helper-reset ui-helper-clearfix">
@foreach (var f in Model.Attachments)
{
    <li class="ui-widget-content ui-corner-tr">
    @if (f.isImage)
    {
        <img width="120" src="@f.ASource" alt="@f.AName" title="@f.AName" />
        <span data-href="@f.ASource" title="@f.AName" class="zoomImg ui-icon ui-icon-zoomin float-left"></span>
        <span data-id="@f.AId" class="deleteAtt ui-icon ui-icon-trash float-right"></span>
        <span data-id="@f.AId" class="setCover ui-icon ui-icon-folder-collapsed float-right"></span>
    }
    else
    {
        <img width="120" src="/Images/Txt.png" alt="@f.AName" title="@f.AName" />
        <span data-id="@f.AId" class="deleteAtt ui-icon ui-icon-trash float-right"></span>
    }
    </li>
}
</ul>
